package com.monkey.controller;

import com.monkey.common.aop.LogAnnotation;
import com.monkey.common.cache.Cache;
import com.monkey.vo.ArticleVo;
import com.monkey.vo.Results;
import com.monkey.vo.params.ArticleParam;
import com.monkey.vo.params.PageParams;
import com.monkey.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author：monkey-L
 * @description: ArticleController，均使用json数据格式进行交互
 * @date: 10:46 2021/10/4
 */
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     *功能描述:首页的文章列表
     * @author monkey-L
     */
    @PostMapping
    //加上此注解，代表要对此接口记录日志
    @LogAnnotation(module="文章",operator="获取文章列表")
    @Cache(expire = 5 * 60 * 1000, name = "listArticle")
    public Results listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticles(pageParams);
    }
    /*
     * 功能描述:首页，最热文章
     * @author monkey-L
     */
    @PostMapping("hot")
    @Cache(expire = 5 * 60 * 1000, name = "hot_article")
    public Results hotArticle() {
        int limit = 5;
        return articleService.hotArticle(limit);
    }
    /*
     * 功能描述:首页，最新文章
     * @author monkey-L
     */
    @PostMapping("new")
    @Cache(expire = 5 * 60 * 1000, name = "news_article")
    public Results newArticles() {
        int limit = 5;
        return articleService.newArticles(limit);
    }
    /*
     * 功能描述:首页，文章归档
     * @author monkey-L
     */
    @PostMapping("listArchives")
    public Results listArchives() {
        return articleService.listArchives();
    }

    /*
     * 功能描述:根据id查看文章详情
     * @author monkey-L
     * @return
     */
    @PostMapping("view/{id}")
    public Results findArticleById(@PathVariable("id") Long id) {
        return articleService.findArticleById(id);
    }

    /*
     * 功能描述: 发布文章
     * @author monkey-L
     * @return
     */
    @PostMapping("publish")
    public Results publish(@RequestBody ArticleParam articleParam) {
        return articleService.publish(articleParam);
    }
}
